package 笔试.便利蜂;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Demo1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] arr = str.split(",");
        int[] nums = new int[arr.length];
        Set<Integer> sets = new HashSet<>();
        Set<Integer> dict = new HashSet<>();
        //int min =Integer.MAX_VALUE;
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            nums[i] = Integer.valueOf(arr[i]);
            dict.add(nums[i]);
            //min = Math.min(min,nums[i]);
        }
        if(nums.length<=1){
            System.out.println(0);
        }else{
            for (int i = 0; i < nums.length; i++) {
                if(!sets.add(nums[i])){
                    int tmp = nums[i];
                    while(dict.contains(tmp)){
                        tmp++;
                    }
                    dict.add(tmp);
                    count += (tmp-nums[i]);
                }
            }
            System.out.println(count);
        }
    }

}
